﻿<UserControl x:Class="Ogdi.Data.DataLoaderUIMvvm.Views.CsvProducerControlView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:WpfToolkit="http://schemas.microsoft.com/wpf/2008/toolkit"
    xmlns:my="http://schemas.microsoft.com/wpf/2008/toolkit" xmlns:Controls="clr-namespace:Ogdi.Data.DataLoaderUIMvvm.Controls" xmlns:ViewModels="clr-namespace:Ogdi.Data.DataLoaderUIMvvm.ViewModels">
    <UserControl.Resources>
        <ResourceDictionary>
            <Style x:Key="BaseLabelCellStyle" TargetType="{x:Type Label}">
                <Setter Property="IsEnabled" Value="{Binding IsEnabled}"/>
                <Setter Property="Margin" Value="0,-3,0,0"/>
            </Style>
            <Style x:Key="BaseComboBoxBoxCellStyle" TargetType="{x:Type ComboBox}">
                <Setter Property="IsEnabled" Value="{Binding IsEnabled}"/>
            </Style>
            <Style x:Key="BaseTextBoxCellStyle" TargetType="{x:Type TextBox}">
                <Setter Property="IsEnabled" Value="{Binding IsEnabled}"/>
            </Style>

            <Style x:Key="RightAlignedLabel" TargetType="Label" >
                <Setter Property="Margin" Value="0,0,4,0" />
                <Setter Property="HorizontalAlignment" Value="Left" />
                <Setter Property="VerticalAlignment" Value="Center" />
            </Style>
            <Style x:Key="RightAlignedTextBlock" TargetType="TextBlock" >
                <Setter Property="Margin" Value="0,0,4,0" />
                <Setter Property="HorizontalAlignment" Value="Left" />
                <Setter Property="VerticalAlignment" Value="Center" />
                <Setter Property="Foreground" Value="{DynamicResource TextBrush}"/>
            </Style>

            <DataTemplate x:Key="ComboBoxCellDataTemplate">
                <Label x:Name="lblCombo" Content="{Binding Type}" Style="{StaticResource BaseLabelCellStyle}" />
                <DataTemplate.Triggers>
                    <DataTrigger Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.EntityPopertyTypes}" Value="Both">
                        <Setter TargetName="lblCombo" Property="IsEnabled" Value="False" />
                    </DataTrigger>
                </DataTemplate.Triggers>
            </DataTemplate>
            <DataTemplate x:Key="ComboBoxCellEditingTemplate">
                <ComboBox x:Name="comboBox" ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.EntityPopertyTypes}" SelectedItem="{Binding Type}"/>
                <DataTemplate.Triggers>
                    <DataTrigger Binding="{Binding Enabled}" Value="False">
                        <Setter TargetName="comboBox" Property="IsEnabled" Value="False" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding EntityPopertyTypes}" Value="Both">
                        <Setter TargetName="comboBox" Property="IsEnabled" Value="False" />
                    </DataTrigger>
                </DataTemplate.Triggers>
            </DataTemplate>

            <DataTemplate x:Key="ComboBoxCellDataTemplate1">
                <Label x:Name="lblCombo" Content="{Binding IndexInName}" Style="{StaticResource BaseLabelCellStyle}" />
                <DataTemplate.Triggers>
                    <DataTrigger Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.IndexInNames}" Value="Both">
                        <Setter TargetName="lblCombo" Property="IsEnabled" Value="False" />
                    </DataTrigger>
                </DataTemplate.Triggers>
            </DataTemplate>
            <DataTemplate x:Key="ComboBoxCellEditingTemplate1">
                <ComboBox x:Name="comboBox" ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.IndexInNames}" SelectedItem="{Binding IndexInName}"/>
                <DataTemplate.Triggers>
                    <DataTrigger Binding="{Binding Enabled}" Value="False">
                        <Setter TargetName="comboBox" Property="IsEnabled" Value="False" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.IndexInName}" Value="Both">
                        <Setter TargetName="comboBox" Property="IsEnabled" Value="False" />
                    </DataTrigger>
                </DataTemplate.Triggers>
            </DataTemplate>
        </ResourceDictionary>
    </UserControl.Resources>

    <Grid VerticalAlignment="Stretch">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="15" />
            <ColumnDefinition Width="auto" />
        </Grid.ColumnDefinitions>

        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition MaxWidth="75"/>
                <ColumnDefinition MaxWidth="75" />
                <ColumnDefinition Width="auto" />
            </Grid.ColumnDefinitions>

            <Label Padding="10" VerticalAlignment="Top" HorizontalAlignment="Left">Entity fields:</Label>


            <my:DataGrid Grid.Row="0" Grid.ColumnSpan="4" AutoGenerateColumns="False" ItemsSource="{Binding PropertyToTypeMaps}" SelectedItem="{Binding SelectedItem}" >
                <my:DataGrid.Columns>
                    <Controls:LabelTextBoxColumn
					Header="Column Name" Width="200"
					HorizontalAlignment="Left" VerticalAlignment="Center"
					ElementStyle="{StaticResource BaseLabelCellStyle}"
					EditingElementStyle="{StaticResource BaseTextBoxCellStyle}"
					Binding="{Binding Path=Name}"/>

                    <WpfToolkit:DataGridTemplateColumn Width="100" 
					Header="Data Type"
					CellTemplate="{StaticResource ComboBoxCellDataTemplate}"
					CellEditingTemplate="{StaticResource ComboBoxCellEditingTemplate}"/>

                    <WpfToolkit:DataGridTemplateColumn Width="100"
					Header="Push Pin Mapping"
					CellTemplate="{StaticResource ComboBoxCellDataTemplate1}"
					CellEditingTemplate="{StaticResource ComboBoxCellEditingTemplate1}"/>

                </my:DataGrid.Columns>
            </my:DataGrid>
        </Grid>


        <Grid Grid.Column="2" Margin="4,34,4,4">
            <Grid.RowDefinitions>
                <RowDefinition Height="auto" />
                <RowDefinition Height="auto" />
                <RowDefinition Height="auto" />
                <RowDefinition Height="auto" />
                <RowDefinition Height="auto" />
                <RowDefinition Height="auto" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition  Width="150" />
                <ColumnDefinition Width="150" />
            </Grid.ColumnDefinitions>

            <CheckBox Grid.Row="0" Name="chbPlacamark" IsChecked="{Binding PlacemarksEnabled}"  Foreground="Black">Bind To Map</CheckBox>
            <Label Grid.Row="1" Grid.ColumnSpan="2" Style="{StaticResource RightAlignedLabel}">Map Push Pin Text Format String:</Label>
            <TextBox Grid.Row="2" Grid.ColumnSpan="2" Name="nameFormatCtr" Text="{Binding NamePropertyFormatString}" VerticalAlignment="Top" IsEnabled="{Binding PlacemarksEnabled}" />
            <TextBlock Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2"  TextWrapping="Wrap" Foreground="Black"  
						Style="{StaticResource RightAlignedTextBlock}">(Example: Suppose the dataset contains columns named A and B and you would like push pins text to read as "valueof(A) - valueof(B)". To achieve that place symbols {0} and {1} into the Push Pin Mapping column against A and B respectively and enter {0} - {1} into the Map Push Pin Format String text field.)</TextBlock>
            <Label Grid.Row="4" Grid.Column="0" Style="{StaticResource RightAlignedLabel}" >Longitude Column Name:</Label>
            <Label Grid.Row="4" Grid.Column="1" Style="{StaticResource RightAlignedLabel}">Latitude Column Name:</Label>
            <ComboBox Grid.Row="5" Grid.Column="0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="120" ItemsSource="{Binding Longitudes}" DisplayMemberPath="Name" SelectedItem="{Binding CurrentLongitude}" IsEnabled="{Binding PlacemarksEnabled}" />
            <ComboBox Grid.Row="5" Grid.Column="1" VerticalAlignment="Top" HorizontalAlignment="Left" Width="120" ItemsSource="{Binding Latitudes}" DisplayMemberPath="Name" SelectedItem="{Binding CurrentLatitude}" IsEnabled="{Binding PlacemarksEnabled}" />
        </Grid>

    </Grid>
</UserControl>
